import {
    reqAddress,
    req_FoodList,
    req_ShopsList,
    req_GoodsList_Mock,
    req_GooderInfo_Mock,
    req_ratingsList_Mock
} from '../req/req_fun.js'

export default {
    // 获取地址
    async get_address(context) {
        let geohash = context.state.latitude + ',' + context.state.longitude;
        // console.log(geohash);
        const result =  await reqAddress(geohash);  
        if(result.code === 0) {
            context.commit('GET_ADDRESS', result.data);
        }else {
            alert('出错啦!')
        }
    },
    // 获取食品分类列表
    async get_food_list(context) {
        const result =  await req_FoodList();  
        if(result.code === 0) {
            context.commit('GET_FOOD_LIST', result.data);
        }else {
            alert('出错啦!')
        }
    },
    // 获取商铺列表
    async get_shops_list(context) {
        const result =  await req_ShopsList({
            latitude: context.state.latitude,
            longitude: context.state.longitude
        });  
        if(result.code === 0) {
            context.commit('GET_SHOPS_LIST', result.data);
        }else {
            alert('出错啦!')
        }
    },

    // 获取商品列表mock
    async get_goods_list(context) {
        const {data: res_data} =  await req_GoodsList_Mock();  
        context.commit('GET_GOODS_LIST', res_data.data);
    },
    // 获取商家信息mock
    async get_gooderInfo(context) {
        const {data: res_data} =  await req_GooderInfo_Mock();  
        context.commit('GET_GOODERINFO', res_data.data);
    },
    // 获取评论列表mock
    async get_ratingsList(context) {
        const {data: res_data} =  await req_ratingsList_Mock();  
        context.commit('GET_RATINGSLIST', res_data.data);
    }
}